{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
	<div class="gg-form-bar border-t border-x">
		<form class="layui-form" lay-filter="barsearchform">
			<div class="layui-input-inline" style="width:240px;">
				<input type="text" name="project_name" placeholder="所属项目" readonly class="layui-input picker-oa" data-types="project" autocomplete="off" />
				<input name="project_id" style="display: none;" value="" />
			</div>
			<div class="layui-input-inline" style="width:300px;">
				<input type="text" name="keywords" placeholder="关键字" class="layui-input" autocomplete="off" />
			</div>
			<div class="layui-input-inline" style="width:150px;">
				<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="table-search"><i class="layui-icon layui-icon-search mr-1"></i>搜索</button>
				<button type="reset" class="layui-btn layui-btn-reset" lay-filter="table-reset">清空</button>
			</div>
		</form>
	</div>
	<table class="layui-hide" id="document" lay-filter="document"></table>
</div>
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
  	<button class="layui-btn layui-btn-sm" lay-event="add">+ 新建文档</button>
  </div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool','tablePlus','oaPicker'];
	function gouguInit() {
		var table = layui.tablePlus, form = layui.form, tool = layui.tool;

		layui.documentTable = table.render({
			elem: '#document',
			title: '文档列表',
			toolbar: '#toolbarDemo',
			is_excel: true,
			cellMinWidth: 80,
			height: 'full-114',
			url: "/project/document/datalist",
			cols: [[
				{
					field: 'id', title: '文档编号', width: 90, align: 'center', templet: function (d) {
						return 'D' + d.id;
					}
				}
				, {
					field: 'title', title: '文档主题',minWidth:240, templet: function (d) {
						var html = '<a class="side-a" data-href="/project/document/view/id/' + d.id + '">' + d.title + '</a>';
						return html;
					}
				}
				, { field: 'project', title: '关联项目', width: 240,}
				, { field: 'admin_name', title: '创建人', align: 'center', width: 80 }
				, { field: 'create_time', title: '创建时间', align: 'center', width: 150 }
				,{
					field: 'right',
					fixed:'right',
					title: '操作',
					width: 120,
					align: 'center',
					templet: function (d) {
						var html = '<div class="layui-btn-group">';
						var btn1='<span class="layui-btn layui-btn-normal layui-btn-xs" lay-event="view">详细</span>';
						var btn2='<span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span>';
						var btn3='<span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span>';
						return html+btn1+btn2+btn3+'</div>';
					}						
				}
			]]
		});
		
		
		//触发事件
		table.on('toolbar(document)', function(obj){
			if (obj.event === 'add') {
				tool.side("/project/document/add");
				return;
			}
		});
		
		//监听行工具事件
		table.on('tool(document)', function(obj) {
			var data = obj.data;
			if (obj.event === 'view') {
				tool.side("/project/document/view?id="+data.id);
				return;
			}
			if(obj.event === 'edit'){
				tool.side('/project/document/add?id='+data.id);
				return;
			}
			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', {
					icon: 3,
					title: '提示'
				}, function(index) {
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/project/document/delete", {id: data.id}, callback);
					layer.close(index);
				});
			}
		});
	}		
</script>
{/block}
<!-- /脚本 -->